import java.util.ArrayList;

/**
 * 
 */

/**
 * @author florian
 *
 */
public class Runner implements java.lang.Comparable
{
	int _ID;
	String _login;
	String _password;
	Group _group;
	ArrayList<Training> _trainings;
	double _score;
	
	static int current_ID=0;
	
	public Runner()
	{
	}
	
	public Runner(String login, String password, Group group, ArrayList<Training> trainings) 
	{
		super();
		_ID = current_ID;
		_login = login;
		_password = password;
		_group = group;
		_trainings = trainings;
		current_ID++;
	}
	
	public Runner(String login, String password) 
	{
		super();
		_ID = current_ID;
		_login = login;
		_password = password;
		_group = null;
		_trainings = new ArrayList<Training>(0);
		current_ID++;
	}
	
	public Runner(int id, String login, String password, Group group, ArrayList<Training> trainings) 
	{
		super();
		_ID = id;
		_login = login;
		_password = password;
		_group = group;
		_trainings = trainings;
		current_ID++;
	}
	
	public void updateScore() {
		double score = 0;
		for(int i=0;i<_trainings.size();i++)
		{
			score = score + _trainings.get(i)._distance;
		}
		_score = score;
	}

	@Override
	public int compareTo(Object other) {
	      double score1 = ((Runner) other)._score; 
	      double score2 = this._score;
	      if (score1 > score2)  return -1; 
	      else if(score1 == score2) return 0; 
	      else return 1; 
	}
	
	public String ToString()
	{
		return("[" + _group + "] " + _login + " with " + _score + " points");
	}

}